package com.project.cris.SessionBean;

import java.util.ArrayList;


import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.Query;

import javax.ejb.LocalBean;
import javax.persistence.PersistenceContext;


import com.project.cris.SessionBean.Search_RoomForRentRemote;
import com.project.entity.RoomForRent;

@Stateless
@LocalBean
public class Search_RoomForRentBean implements Search_RoomForRentRemote {
	@PersistenceContext
	EntityManager em;
	public ArrayList<RoomForRent> getAllRoomForRent() throws Exception {
		// TODO Auto-generated method stub
		Query query = em.createNamedQuery("RoomForRent.findAllRoomForRent");
		@SuppressWarnings("unchecked")
		ArrayList<RoomForRent> result = (ArrayList<RoomForRent>) query
				.getResultList();
		return result;
	}
	@SuppressWarnings("unchecked")
	@Override
	public ArrayList<RoomForRent> searchRoomForRent(String title,
			String address, double depositMin, double depositMax,
			double RentMin, double RentMax) {
		Query query=em.createNamedQuery("RoomForRent.searchRoomForRent");
			query.setParameter("title", "%"+title+"%");
			query.setParameter("address", "%"+address+"%");
			query.setParameter("depositMin", depositMin);
			query.setParameter("depositMax", depositMax);
			query.setParameter("rentMin", RentMin);
			query.setParameter("rentMax", RentMax);
		return (ArrayList<RoomForRent>) query.getResultList();
	}
}
